using System;

namespace OracleInternal.Common
{
	internal class ByteBuffer
	{
		internal byte[] m_byteBuffer;

		internal int m_capacity;

		internal int m_position;

		internal int m_limit;

		internal bool HasRemaining
		{
			get
			{
				if (m_limit <= m_position)
				{
					return false;
				}
				return true;
			}
		}

		internal int Remaining => m_limit - m_position;

		internal int Limit
		{
			get
			{
				return m_limit;
			}
			set
			{
				m_limit = value;
			}
		}

		internal ByteBuffer()
		{
			m_byteBuffer = null;
			m_limit = (m_capacity = (m_position = 0));
		}

		internal ByteBuffer(int capacity)
		{
			m_byteBuffer = new byte[capacity];
			m_capacity = capacity;
			m_limit = (m_position = 0);
		}

		internal void GetBufferRef(out byte[] userBuff, out int offset, int length)
		{
			if (length <= Remaining)
			{
				userBuff = m_byteBuffer;
				offset = m_position;
				m_position += length;
				return;
			}
			throw new ArgumentOutOfRangeException("length");
		}

		internal void GetBuffer(byte[] userBuff, int offset, int length)
		{
			if (length <= Remaining)
			{
				Array.Copy(m_byteBuffer, m_position, userBuff, offset, length);
				m_position += length;
				return;
			}
			throw new ArgumentOutOfRangeException("length");
		}

		internal byte GetByte()
		{
			return m_byteBuffer[m_position++];
		}

		internal short GetShort()
		{
			int num = m_byteBuffer[m_position++] & 0xFF;
			int num2 = m_byteBuffer[m_position++] & 0xFF;
			return (short)(((num << 8) | num2) & 0xFFFF);
		}

		internal int GetInt()
		{
			int num = m_byteBuffer[m_position++] & 0xFF;
			int num2 = m_byteBuffer[m_position++] & 0xFF;
			int num3 = m_byteBuffer[m_position++] & 0xFF;
			int num4 = m_byteBuffer[m_position++] & 0xFF;
			return (num << 24) | (num2 << 16) | (num3 << 8) | num4;
		}

		internal long GetLong()
		{
			long num = (long)m_byteBuffer[m_position++] & 0xFFL;
			long num2 = (long)m_byteBuffer[m_position++] & 0xFFL;
			long num3 = (long)m_byteBuffer[m_position++] & 0xFFL;
			long num4 = (long)m_byteBuffer[m_position++] & 0xFFL;
			long num5 = (long)m_byteBuffer[m_position++] & 0xFFL;
			long num6 = (long)m_byteBuffer[m_position++] & 0xFFL;
			long num7 = (long)m_byteBuffer[m_position++] & 0xFFL;
			long num8 = (long)m_byteBuffer[m_position++] & 0xFFL;
			return (num << 56) | (num2 << 48) | (num3 << 40) | (num4 << 32) | (num5 << 24) | (num6 << 16) | (num7 << 8) | num8;
		}
	}
}
